package com.mk.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mk.entity.Insurance;
import com.mk.entity.Vaccine;
import com.mk.result.Result;
import com.mk.service.InsuranceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 医疗保险情况业务
 */
@RestController
@RequestMapping("/user/insurance")
@RequiredArgsConstructor
public class InsuranceController {

    private final InsuranceService insuranceService;

    /**
     * 医疗保险情况登记
     * @param insurance
     * @return
     */
    @CrossOrigin
    @PostMapping("/save")
    public Result saveInsurance(@RequestBody Insurance insurance) {
        insurance.setStatus(Insurance.NORMAL);
        insurance.setCreateTime(LocalDateTime.now());
        insurance.setUpdateTime(LocalDateTime.now());
        insuranceService.save(insurance);
        return Result.success();
    }

    /**
     * 根据宠物id获取所有医疗保险情况信息
     * @param petId
     * @return
     */
    @CrossOrigin
    @GetMapping("/ids")
    public Result<List<Insurance>> getAllInsurances(Long petId) {
        List<Insurance> list = insuranceService.list(new LambdaQueryWrapper<Insurance>()
                .eq(Insurance::getPetId, petId));
        return Result.success(list);
    }

    /**
     * 根据id删除医疗保险情况信息
     * @param id
     * @return
     */
    @CrossOrigin
    @DeleteMapping("/delete/{id}")
    public Result deleteInsurance(@PathVariable Long id) {
        insuranceService.removeById(id);
        return Result.success();
    }
}
